﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Compilex.Syntatic
{
    public class ScopeManager
    {
        public ScopeManager()
        {
            this.CurrentScope = new Scope();
        }
        public Scope CurrentScope { get; set; }

        public Scope OpenScope()
        {
            if (CurrentScope == null)
                throw new InternalSyntaticException("Escopo atual nulo");
            Scope newScope = new Scope();
            newScope.ParentScope = CurrentScope;
            CurrentScope = newScope;
            return CurrentScope;
        }

        public void CloseScope()
        {
            if (CurrentScope == null)
                throw new InternalSyntaticException("Escopo atual nulo");
            Scope parentScope = CurrentScope.ParentScope;
            CurrentScope = parentScope;
            if (CurrentScope == null)
            {
                throw new SyntaticException("O escopo global nao pode ser fechado");
            }
        }
    }
}
